﻿var FY0 = "┏━━━━━━━━━━━┓";
var FY1 = "┃       - 枫叶 -       ┃";
var FY2 = "┃ 脚本仿制  　定制脚本 ┃";
var FY3 = "┃ 技术支持 　 游戏顾问 ┃";
var FY4 = "┃ ＷＺ添加　  地图制作 ┃";
var FY5 = "┃ 加盾防御　  售登陆器 ┃";
var FY6 = "┣━━━━━━━━━━━┫";
var FY7 = "┃ 唯一QQ:1848350048    ┃";
var FY8 = "┗━━━━━━━━━━━┛";
var 红色箭头 = "#fUI/UIWindow/Quest/icon6/7#";
var 正方箭头 = "#fUI/Basic/BtHide3/mouseOver/0#";
var status = 0;
//普通奖池
var itemList1 = [
	//物品id，几率，数字越大概率越大，数量


[2049304, 25, 1, 1],//升星卷轴
[2049100, 15, 1, 1],//混沌卷轴	
[2340000, 15, 1, 1],//祝福卷轴
[2040212, 15, 1, 1],
[2040211, 40, 1, 1],
[2040001, 40, 1, 1],
[2040004, 40, 1, 1],
[2040002, 30, 1, 1],
[2040005, 30, 1, 1],
[2040025, 20, 1, 1],
[2040026, 10, 1, 1],
[2040029, 20, 1, 1],
[2040031, 10, 1, 1],
[2040233, 5, 1, 1],
[2040234, 5, 1, 1],
[2040235, 5, 1, 1],
[2040236, 5, 1, 1],
[2040301, 20, 1, 1],
[2040301, 10, 1, 1],
[2040317, 20, 1, 1],
[2040318, 10, 1, 1],
[2040321, 20, 1, 1],
[2040323, 10, 1, 1],
[2040328, 40, 1, 1],
[2040401, 40, 1, 1],
[2040402, 30, 1, 1],
[2040418, 20, 1, 1],
[2040419, 10, 1, 1],
[2040421, 40, 1, 1],
[2040422, 30, 1, 1],
[2040425, 20, 1, 1],
[2040427, 10, 1, 1],
[2040501, 20, 1, 1],
[2040502, 10, 1, 1],
[2040504, 40, 1, 1],
[2040505, 30, 1, 1],
[2040513, 20, 1, 1],
[2040514, 10, 1, 1],
[2040516, 20, 1, 1],
[2040517, 10, 1, 1],
[2040532, 20, 1, 1],
[2040534, 10, 1, 1],
[2040601, 40, 1, 1],
[2040602, 30, 1, 1],
[2040618, 40, 1, 1],
[2040618, 30, 1, 1],
[2040621, 40, 1, 1],
[2040622, 30, 1, 1],
[2040625, 20, 1, 1],
[2040627, 10, 1, 1],
[2040701, 20, 1, 1],
[2040702, 10, 1, 1],
[2040704, 20, 1, 1],
[2040705, 10, 1, 1],
[2040707, 20, 1, 1],
[2040708, 10, 1, 1],
[2040727, 5, 1, 1],
[2040801, 20, 1, 1],
[2040801, 10, 1, 1],
[2040804, 20, 1, 1],
[2040805, 10, 1, 1],
[2040824, 40, 1, 1],
[2040825, 30, 1, 1],
[2040845, 20, 1, 1],
[2040901, 40, 1, 1],
[2040902, 30, 1, 1],
[2040924, 20, 1, 1],
[2040925, 10, 1, 1],
[2040927, 40, 1, 1],
[2040928, 30, 1, 1],
[2040931, 20, 1, 1],
[2040933, 10, 1, 1],
[2041001, 40, 1, 1],
[2041002, 30, 1, 1],
[2041007, 40, 1, 1],
[2041008, 30, 1, 1],
[2041010, 40, 1, 1],
[2041011, 30, 1, 1],
[2041013, 20, 1, 1],
[2041014, 10, 1, 1],
[2041016, 20, 1, 1],
[2041017, 10, 1, 1],
[2041019, 20, 1, 1],
[2041022, 20, 1, 1],
[2041023, 10, 1, 1],
[2041101, 5, 1, 1],
[2041102, 5, 1, 1],
[2041104, 5, 1, 1],
[2041105, 5, 1, 1],
[2041107, 5, 1, 1],
[2041108, 5, 1, 1],
[2041110, 5, 1, 1],
[2043811, 5, 1, 1],
[2041301, 5, 1, 1],
[2041302, 5, 1, 1],
[2041305, 5, 1, 1],
[2041307, 5, 1, 1],
[2041308, 5, 1, 1],
[2041310, 5, 1, 1],
[2041311, 5, 1, 1],
[2041304, 5, 1, 1],
[2043001, 20, 1, 1],
[2043002, 10, 1, 1],
[2043017, 30, 1, 1],
[2043019, 30, 1, 1],
[2043101, 30, 1, 1],
[2043101, 30, 1, 1],
[2043112, 30, 1, 1],
[2043114, 30, 1, 1],
[2043201, 30, 1, 1],
[2043202, 30, 1, 1],
[2043212, 30, 1, 1],
[2043214, 30, 1, 1],
[2043301, 30, 1, 1],
[2043302, 30, 1, 1],
[2043701, 30, 1, 1],
[2043702, 30, 1, 1],
[2043801, 30, 1, 1],
[2043802, 30, 1, 1],
[2044212, 30, 1, 1],
[2044214, 30, 1, 1],
[2044301, 30, 1, 1],
[2044302, 30, 1, 1],
[2044312, 30, 1, 1],
[2044314, 30, 1, 1],
[2044401, 30, 1, 1],
[2044402, 30, 1, 1],
[2044412, 30, 1, 1],
[2044414, 30, 1, 1],
[2044501, 30, 1, 1],
[2044502, 30, 1, 1],
[2044601, 30, 1, 1],
[2044602, 30, 1, 1],
[2044701, 20, 1, 1],
[2044702, 10, 1, 1],
[2044801, 30, 1, 1],
[2044802, 30, 1, 1],
[2044901, 30, 1, 1],
[2044902, 30, 1, 1],
[2040816, 10, 1, 1],
[4032391, 5, 1, 1],
[4032392, 5, 1, 1],
[4250002, 5, 1, 1],
[4250102, 5, 1, 1],
[4250202, 5, 1, 1],
[4250302, 5, 1, 1],
[4250402, 5, 1, 1],
[4250502, 5, 1, 1],
[4250602, 5, 1, 1],
[4250702, 5, 1, 1],
[4250802, 5, 1, 1],
[4250902, 5, 1, 1],
[4251002, 5, 1, 1],
[4251102, 5, 1, 1],
[4251202, 5, 1, 1],
[4251302, 5, 1, 1],
[4251402, 5, 1, 1],
[4250001, 10, 1, 1],
[4250101, 10, 1, 1],
[4250201, 10, 1, 1],
[4250301, 10, 1, 1],
[4250401, 10, 1, 1],
[4250501, 10, 1, 1],
[4250601, 10, 1, 1],
[4250701, 10, 1, 1],
[4250801, 10, 1, 1],
[4250901, 10, 1, 1],
[4251001, 10, 1, 1],
[4251101, 10, 1, 1],
[4251201, 10, 1, 1],
[4251301, 10, 1, 1],
[4251401, 10, 1, 1],
[4250000, 15, 1, 1],
[4250100, 15, 1, 1],
[4250200, 15, 1, 1],
[4250300, 15, 1, 1],
[4250400, 15, 1, 1],
[4250500, 15, 1, 1],
[4250600, 15, 1, 1],
[4250700, 15, 1, 1],
[4250800, 15, 1, 1],
[4250900, 15, 1, 1],
[4251000, 15, 1, 1],
[4251100, 15, 1, 1],
[4251200, 15, 1, 1],
[4251300, 15, 1, 1],
[4251400, 15, 1, 1],
[2280004, 1, 1, 1],
[2280005, 1, 1, 1],
[2280006, 1, 1, 1],
[2280007, 1, 1, 1],
[2280008, 1, 1, 1],
[2280009, 1, 1, 1],
[2280010, 1, 1, 1],
[2280012, 1, 1, 1],
[2280013, 1, 1, 1],
[2280014, 1, 1, 1],
[2280015, 1, 1, 1],
[2290000, 5, 1, 1],
[2290001, 5, 1, 1],
[2290002, 5, 1, 1],
[2290003, 5, 1, 1],
[2290004, 5, 1, 1],
[2290005, 5, 1, 1],
[2290006, 5, 1, 1],
[2290007, 5, 1, 1],
[2290008, 5, 1, 1],
[2290009, 5, 1, 1],
[2290010, 5, 1, 1],
[2290011, 5, 1, 1],
[2290012, 5, 1, 1],
[2290013, 5, 1, 1],
[2290014, 5, 1, 1],
[2290015, 5, 1, 1],
[2290016, 5, 1, 1],
[2290017, 5, 1, 1],
[2290018, 5, 1, 1],
[2290019, 5, 1, 1],
[2290020, 5, 1, 1],
[2290021, 5, 1, 1],
[2290022, 5, 1, 1],
[2290023, 5, 1, 1],
[2290024, 5, 1, 1],
[2290025, 5, 1, 1],
[2290026, 5, 1, 1],
[2290027, 5, 1, 1],
[2290028, 5, 1, 1],
[2290029, 5, 1, 1],
[2290030, 5, 1, 1],
[2290031, 5, 1, 1],
[2290032, 5, 1, 1],
[2290033, 5, 1, 1],
[2290034, 5, 1, 1],
[2290035, 5, 1, 1],
[2290036, 5, 1, 1],
[2290037, 5, 1, 1],
[2290038, 5, 1, 1],
[2290039, 5, 1, 1],
[2290040, 5, 1, 1],
[2290041, 5, 1, 1],
[2290042, 5, 1, 1],
[2290043, 5, 1, 1],
[2290044, 5, 1, 1],
[2290045, 5, 1, 1],
[2290046, 5, 1, 1],
[2290047, 5, 1, 1],
[2290048, 5, 1, 1],
[2290049, 5, 1, 1],
[2290050, 5, 1, 1],
[2290051, 5, 1, 1],
[2290052, 5, 1, 1],
[2290053, 5, 1, 1],
[2290054, 5, 1, 1],
[2290055, 5, 1, 1],
[2290056, 5, 1, 1],
[2290057, 5, 1, 1],
[2290058, 5, 1, 1],
[2290059, 5, 1, 1],
[2290060, 5, 1, 1],
[2290061, 5, 1, 1],
[2290062, 5, 1, 1],
[2290063, 5, 1, 1],
[2290064, 5, 1, 1],
[2290065, 5, 1, 1],
[2290066, 5, 1, 1],
[2290067, 5, 1, 1],
[2290068, 5, 1, 1],
[2290069, 5, 1, 1],
[2290070, 5, 1, 1],
[2290071, 5, 1, 1],
[2290072, 5, 1, 1],
[2290073, 5, 1, 1],
[2290074, 5, 1, 1],
[2290075, 5, 1, 1],
[2290076, 5, 1, 1],
[2290077, 5, 1, 1],
[2290078, 5, 1, 1],
[2290079, 5, 1, 1],
[2290080, 5, 1, 1],
[2290081, 5, 1, 1],
[2290082, 5, 1, 1],
[2290083, 5, 1, 1],
[2290084, 5, 1, 1],
[2290085, 5, 1, 1],
[2290086, 5, 1, 1],
[2290087, 5, 1, 1],
[2290088, 5, 1, 1],
[2290089, 5, 1, 1],
[2290090, 5, 1, 1],
[2290091, 5, 1, 1],
[2290092, 5, 1, 1],
[2290093, 5, 1, 1],
[2290094, 5, 1, 1],
[2290095, 5, 1, 1],
[2290096, 5, 1, 1],
[2290097, 5, 1, 1],
[2290098, 5, 1, 1],
[2290099, 5, 1, 1],
[2290101, 5, 1, 1],
[2290102, 5, 1, 1],
[2290103, 5, 1, 1],
[2290104, 5, 1, 1],
[2290105, 5, 1, 1],
[2290106, 5, 1, 1],
[2290107, 5, 1, 1],
[2290108, 5, 1, 1],
[2290110, 5, 1, 1],
[2290111, 5, 1, 1],
[2290112, 5, 1, 1],
[2290113, 5, 1, 1],
[2290114, 5, 1, 1],
[2290115, 5, 1, 1],
[2290116, 5, 1, 1],
[2290117, 5, 1, 1],
[2290118, 5, 1, 1],
[2290119, 5, 1, 1],
[2290120, 5, 1, 1],
[2290121, 5, 1, 1],
[2290122, 5, 1, 1],
[2290123, 5, 1, 1],
[2290124, 5, 1, 1],
[2290125, 5, 1, 1],
[2290126, 5, 1, 1],
[2290127, 5, 1, 1],
[2290128, 5, 1, 1],
[2290129, 5, 1, 1],
[2290130, 5, 1, 1],
[2290131, 5, 1, 1],
[2290132, 5, 1, 1],
[2290133, 5, 1, 1],
[2290134, 5, 1, 1],
[2290135, 5, 1, 1],
[2290136, 5, 1, 1],
[2290137, 5, 1, 1],
[2290138, 5, 1, 1],
[2290139, 5, 1, 1]

];

var useNx = 10000000;
var sel0 = -1;
function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (status == 0 && mode == 0) {
        cm.dispose();
        return;
    }
    if (mode == 1) {
        status++;
    } else {
        status--;
    }

    if (status == 0) {
    	var txt = "#d\t\t\t#b欢迎来到『冒险岛』抽奖中心#n#k\r\n";
    	txt += "#d#L1##b"+红色箭头+"进行抽奖#l\r\n\r\n";
		txt += "\t#b"+正方箭头+"奖品展示： \r\n";
		
		var txt2 = "";
		for (var i = 0; i < itemList1.length;  i++){
			txt2 += "#i"+itemList1[i][0]+":#";
		}
    	cm.sendSimple(txt + txt2);
    } else if (status == 1) {
		var jobid=cm.getPlayer().getJob();
		//if (jobid==112||jobid==122||jobid==132||jobid==212||jobid==222||jobid==232||jobid==312||jobid==322||jobid==412||jobid==422||jobid==512||jobid==522||jobid==2112||jobid==1112||jobid==1111||jobid==1211||jobid==1311||jobid==1411||jobid==1511){
		sel0 = selection;
		cm.sendGetNumber("#d请输入抽奖次数\r\n"
		+"#d金币抽奖1000万金币/次\r\n"
		+"#k\r\n#r当前拥有金币数量: " + cm.getMeso(),
		1, 1, 99999
		);
		//}else {
         //   cm.sendOk("您好，金币抽奖需要您先完成所有转职后才可以进行抽奖哦！");
         //   cm.dispose();
         //   }
	} else if(status == 2) {
		if (!cm.checkNumSpace(0, selection)) {
			cm.sendOk("背包空间不足"+selection+"格");
			cm.dispose();
			return;
		}
    	switch (sel0) {
			case 1:
                if (cm.getMeso() < (useNx*selection)) {
					cm.sendOk("金币不足"+(useNx*selection)+"，无法抽奖");
					cm.dispose();
					return;
				} else {
					cm.gainMeso(-useNx*selection);
				}
				break;
			case 2:
                if (!cm.haveItem(4001126,400*selection)) {
					cm.sendOk("#v4001126#数量不足#r "+(400*selection)+" #k，无法抽奖");
					cm.dispose();
					return;
				} else {
					cm.gainItem(4001126, -(400*selection));
				}
				break;
			default:
				cm.sendOk("脚本出错，请联系管理员");
				cm.dispose();
				return;
        }
		var txt = "恭喜你获得道具：\r\n";
		for (var i = 0; i < selection; i++) {
			var item;
			var ran = Math.floor(Math.random() * 100);
			var ran1 = null;
			ran1 = finalGift(itemList1);
			if(cm.getBossRankCount("屏蔽"+ran1[0]) > 0){
				cm.gainGachaponItem2(4001126, 1, "抽奖机", ran1[3]);
			}else{
				cm.gainGachaponItem2(ran1[0], ran1[2], "抽奖机", 1);
			}
			cm.gainItem(4000313, 1);
			//cm.gainItem(ran1[0] ,ran1[2])
			//cm.worldMessage("『抽奖捷报』：恭喜玩家."+ cm.getChar().getName() +"  获得["+ Packages.server.MapleItemInformationProvider.getInstance().getName(ran1[0]) +"]让我们热烈的祝福他/她吧！");
			txt += "#v" + ran1[0] + "#\r\n";
			var result = cm.setBossRankCount("随机奖池抽奖");
			/*
			var ran2 = null;
			if (result%10 == 0) {//十连抽保底
				ran2 = finalGift(itemList1);
				cm.gainItem(ran2[0] ,ran2[2])
				txt += "额外道具：#v" + ran2[0] + "#\r\n";
			}
			*/
		}
		cm.sendOk(txt);
		cm.dispose();
		return;
    }
}

function finalGift(lists) {
	var maxChance = 0;
	for (var i in lists) {
		if (lists[i][1] > maxChance) {
			maxChance = lists[i][1];
		}
	}
	var chance = Math.floor(Math.random() * maxChance);
	var finalitem = Array();
	for (var i = 0; i < lists.length; i++) {
		if (lists[i][1] >= chance) {
			finalitem.push(lists[i]);
		}
	}
	var ran1 = Math.floor(Math.random() * finalitem.length);
	return finalitem[ran1];
}